package com.graduate.examapp.request

import android.content.Context
import android.util.Log
import com.graduate.examapp.entity.UserInfoFactory
import okhttp3.Interceptor
import okhttp3.Response

class RequestInterceptor(private val context: Context?) : Interceptor {

    override fun intercept(chain: Interceptor.Chain): Response {
        var request = chain.request()
        val path = request.url.encodedPath
        Log.d("RequestInterceptor", path)

        if (path == "/user/login") {
            return chain.proceed(request)
        }

        UserInfoFactory.loginData?.let {
            Log.d("RequestInterceptor", it.jwt)
            request = chain.request().newBuilder()
                .addHeader("jwt", it.jwt)
                .build()

        }
        return chain.proceed(request)

    }

}